package 笔试.网易;

public class Demo2 {

    public static void main(String[] args) {
        System.out.println(findKthBit(3, 2)); //b
    }

    public static char findKthBit (int n, int k) {
        // write code here
        if(k==1) return 'a';
        String[] S = new String[n+1];
        S[1]="a";
        for(int i=2;i<=n;i++){
            StringBuilder sb = new StringBuilder();
            sb.append(S[i-1]);
            sb.append((char)('a'+i-1));
            sb.append(reverse(S,i-1));
            S[i] = sb.toString();
        }
        return S[n].charAt(k-1);

    }

    public static String reverse(String[] str,int index){
        int len = str[index].length();
        String temp = str[index];
        StringBuilder sb = new StringBuilder();
        for(int i=len-1;i>=0;i--){
            char t = (char)('z'-(temp.charAt(i)-'a'));
            sb.append(t);
        }
        return sb.toString();



    }
}
